package transaction_date

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 持有一段时间的统计日
type HoldTimeStatisticsDate struct {
	db *gorm.DB
}

// 初始化
func (h *HoldTimeStatisticsDate) Init(db *gorm.DB) {
	h.db = db
}

// 是否是统计日
func (h *HoldTimeStatisticsDate) IsStatisticsDate(transactionDate string) bool {
	var origin int = 0
	var stockNumber *int = &origin
	h.db.Raw("select count(distinct t.date_) from quant_account_log t where t.date_<to_date(?,'yyyy-mm-dd')", transactionDate).Scan(&stockNumber)
	if (*stockNumber+properties.QuantProperties_.HoldTime)%properties.QuantProperties_.HoldTime == 0 {
		io.Infoln("日期[%s]是统计日", transactionDate)
		return true
	} else {
		//if transactionDate == properties.QuantProperties_.RealtimeBeginDate {
		//	return true
		//} else {
		//	return false
		//}
		return false
	}
}
